package com.itheima.delaytask.config;

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @program: virtual-trade-parent
 * @description: 线程池配置类
 * @author: zhanghz001
 * @create: 2021-07-11 18:32
 **/
// @Configuration
public class ThreadPoolTaskConfiguration {
    // @Bean("delaytask")
    public ThreadPoolTaskExecutor threadPool() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(8);
        executor.setMaxPoolSize(10000);
        executor.setKeepAliveSeconds(60);
        executor.setQueueCapacity(10000);
        executor.setThreadNamePrefix("delaytask-");
        //直接拒绝,抛出异常
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
        //直接初始化
        executor.initialize();
        return executor;
    }
}
